<script setup>
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'
import TitleBadge from './TitleBadge.vue'

const router = useRouter()  

// 输入：用户显示名与认证状态、头像、等级与称号
const props = defineProps({
  userDisplayName: { type: String, default: '' },
  isAuthenticated: { type: Boolean, default: false },
  avatarUrl: { type: String, default: '' },
  level: { type: [Number, String], default: '' },
  title: { type: String, default: '' }
})


const handleToProfile = () => {
  router.push('/profile')
}
</script>

<template>
  <!-- 个人信息卡片：展示头像、名称与登录状态 -->
  <div class="info-section personal-info" @click="handleToProfile">
    <div class="info-content">
      <div class="avatar">
        <el-avatar :size="40" :src="props.avatarUrl">
          <span class="avatar-icon">👤</span>
        </el-avatar>
      </div>
      <div class="user-details">
        <p class="user-name">{{ props.userDisplayName || '游客用户' }}</p>
        <p v-if="!props.isAuthenticated" class="user-status">未登录</p>
        <p v-if="((props.level !== '' && props.level !== null && props.level !== undefined) || props.title)" class="user-meta">
          <span v-if="(props.level !== '' && props.level !== null && props.level !== undefined)" class="level">
            <span class="lv-prefix">LV.</span><span class="lv-number">{{ props.level }}</span>
          </span>
          <span v-if="props.title && (props.level !== '' && props.level !== null && props.level !== undefined)" class="title-dot">·</span>
          <TitleBadge
            v-if="props.title"
            :title="props.title"
            :level="Number(props.level) || 1"
            size="sm"
            :active="true"
          />
        </p>
      </div>
    </div>
  </div>
</template>

<style scoped>
.info-section {
  background: #f9fafb;
  border-radius: 12px;
  padding: 16px;
  border: 1px solid #e5e7eb;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.info-section:hover {
  box-shadow: 0 8px 24px rgba(0,0,0,0.06);
  transform: translateY(-1px);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: #374151;
  margin: 0;
  text-align: center;
  flex: 1;
}

.personal-info .info-content {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-icon {
  font-size: 20px;
}

.user-details { flex: 1; }

.user-name {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 4px 0;
  letter-spacing: 0.2px;
  background: linear-gradient(90deg, #7c3aed 0%, #2563eb 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 1px 1px rgba(0,0,0,0.06);
}

.user-status {
  font-size: 12px;
  color: #6b7280;
  margin: 0;
}

.user-meta {
  margin: 6px 0 0 0;
  font-size: 12px;
  color: #374151;
  display: flex;
  align-items: center;
  gap: 6px;
}

.level {
  font-weight: 800;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  box-shadow: 0 2px 8px rgba(239, 68, 68, 0.25);
}

/* 称号由 TitleBadge 渲染，保留分隔点样式 */
.title-dot { color: #94a3b8; font-weight: 700; }
</style> 